package com.study.sbsummary.controller;

import com.study.sbsummary.model.Goods;
import com.study.sbsummary.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @GetMapping("/listAll")
    public List<Goods> getAllGoods() {
        List<Goods> goodss = goodsService.listGoods();
        return goodss;
    }

    @GetMapping("/get")
    public Goods getById(@RequestParam("id") Long id) {
        Goods goods = goodsService.selectGoodsById(id);
        return goods;
    }

    @PostMapping("/add")
    public Boolean insert(Goods goods) {
        goodsService.addGoods(goods);
        return true;
    }

    @PostMapping("/delById")
    public Boolean delete(@RequestParam("id") Long id) {
        goodsService.deleteGoods(id);
        return true;
    }
}
